package com.googlecode.yoohoo.xmppcore.protocol.translation;

import junit.framework.Assert;

import org.junit.Test;

import com.googlecode.yoohoo.xmppcore.protocol.translation.IXmlWriter;
import com.googlecode.yoohoo.xmppcore.protocol.translation.XmlWriter;

public class XmlWriterTest {
	@Test
	public void toXml() {
		String xml =
			"<iq from='rooms.shakespeare.lit' id='disco-rsm-1' to='hag66@shakespeare.lit/pda' type='result'>" +
				"<query xmlns='http://jabber.org/protocol/disco#items'>" +
					"<item jid='alls-well-that-ends-well@rooms.shakespeare.lit'/>" +
					"<item jid='as-you-like-it@rooms.shakespeare.lit'/>" +
					"<set xmlns='http://jabber.org/protocol/rsm'>" +
						"<first index='0'>alls-well-that-ends-well@rooms.shakespeare.lit</first>" +
						"<last>as-you-like-it@rooms.shakespeare.lit</last>" +
						"<count>2</count>" +
					"</set>" +
				"</query>" +
			"</iq>";
		
		IXmlWriter writer = new XmlWriter();
		writer.writeStartElement("iq");
		writer.writeAttribute("from", "rooms.shakespeare.lit");
		writer.writeAttribute("id", "disco-rsm-1");
		writer.writeAttribute("to", "hag66@shakespeare.lit/pda");
		writer.writeAttribute("type", "result");
		
		writer.writeStartElement("query");
		writer.writeNamespace("http://jabber.org/protocol/disco#items");
		
		writer.writeStartElement("item");
		writer.writeAttribute("jid", "alls-well-that-ends-well@rooms.shakespeare.lit");
		writer.writeEndElement();
		
		writer.writeStartElement("item");
		writer.writeAttribute("jid", "as-you-like-it@rooms.shakespeare.lit");
		writer.writeEndElement();
		
		writer.writeStartElement("set");
		writer.writeNamespace("http://jabber.org/protocol/rsm");
		
		writer.writeStartElement("first");
		writer.writeAttribute("index", Integer.toString(0));
		writer.writeCharacters("alls-well-that-ends-well@rooms.shakespeare.lit");
		writer.writeEndElement();
		
		writer.writeStartElement("last");
		writer.writeCharacters("as-you-like-it@rooms.shakespeare.lit");
		writer.writeEndElement();
		
		writer.writeStartElement("count");
		writer.writeCharacters(Integer.toString(2));
		writer.writeEndElement();
		
		writer.writeEndElement();
		writer.writeEndElement();
		writer.writeEndElement();
		
		Assert.assertEquals(xml, writer.toXml());
	}
}
